package com.yanqu.road.server.gameplayer.module.activity.cookboy;

import com.yanqu.road.entity.enums.activity.eActivityCookBoyType;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.entity.enums.eSystemId;
import com.yanqu.road.pb.cookboyactivity.CookBoyActivityProto;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.RelationActivityModule;
import com.yanqu.road.server.logic.activity.relation.RelationActivityData;
import com.yanqu.road.server.manger.activity.cookboy.CookBoyActivityMgr;
import com.yanqu.road.server.manger.config.SystemOpenMgr;
import com.yanqu.road.server.protocol.Protocol;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CookBoyActivityModule extends RelationActivityModule {

    public CookBoyActivityModule(GamePlayer player) {
        super(player);
    }

    @Override
    public void loginSendMsg() {
        addNewActivity();
        syncActivity();
    }


    //系统解锁了也要来一下
    public void initCookBoySystem() {
        syncActivity();
    }

    public void syncActivity(){
        Map<Integer, Map<Integer, RelationActivityData>> dataMap = new ConcurrentHashMap<>();
        if(SystemOpenMgr.systemOpen(player, eSystemId.CookBoyActivity1.getValue())) {
            addActivityData(dataMap, eActivityType.CookingBoyActivity.getValue(),eActivityCookBoyType.Process1.getChildType());
        }
//        if(SystemOpenMgr.systemOpen(player, eSystemId.CookBoyActivity2.getValue())) {
        addActivityData(dataMap,eActivityType.CookingBoyActivity.getValue(),eActivityCookBoyType.Process2.getChildType());
//        }

//        if(SystemOpenMgr.systemOpen(player, eSystemId.CookBoyActivity3.getValue())) {
        addActivityData(dataMap,eActivityType.CookingBoyActivity.getValue(),eActivityCookBoyType.Process3.getChildType());
//        }

        if(dataMap.size() > 0){
            CookBoyActivityProto.CookBoyActivityDetailMsg.Builder detailMsg = CookBoyActivityMgr.getCookBoyActivityDetailMsg(dataMap, player.getLanguage());
            player.sendPacket(Protocol.U_COOK_BOY_ACTIVITY_DETAIL, detailMsg);
        }
    }
    @Override
    public boolean afterLoadData() {
        return false;
    }

    @Override
    public boolean saveData() {
        return true;
    }

    @Override
    public boolean loadData() {
        activityDataMap = player.getModule(RelationActivityModule.class).getActivityDataMap();
        return true;
    }
}
